package com.leff.cards.web.requests;

import java.util.ArrayList;

import org.json.simple.JSONArray;

import android.util.Log;

import com.leff.cards.data.Invitation;
import com.leff.cards.util.Dictionary;
import com.leff.cards.web.WebRequest;
import com.leff.notifications.NotificationCenter;

public class GetInvitesRequest extends WebRequest {
	
	public static final String INVITES_RECEIVED = "InvitesReceived";
	
	public GetInvitesRequest(long fbid) {
		super(WebCommand.GET_INVITES);

		mParameters.put(Parameter.FB_ID, fbid);
	}

	@Override
	protected void parseResultDictionary(Dictionary dict) {

		ArrayList<Invitation> invitedGroups = new ArrayList<Invitation>();
		
		JSONArray array = (JSONArray)dict.get("invites");
		for(Object O : array) {
			Dictionary invite = Dictionary.fromJSONObject(O);
			invitedGroups.add(Invitation.fromDictionary(invite));
		}
		
		Log.v(TAG, "Completed  parsing GET_INVITES response");
		NotificationCenter.postNotification(INVITES_RECEIVED, invitedGroups);
	}
}
